import logging
import logging.handlers

def init_log_config(filename,when="midnight",interval=1,backupCount=3):
    logger = logging.getLogger()

    logger.setLevel(logging.DEBUG)

    st = logging.StreamHandler()
    fh = logging.handlers.TimedRotatingFileHandler(filename,when=when,interval=interval,backupCount=backupCount,encoding="utf-8")

    fmt =  "%(asctime)s %(levelname)s [%(filename)s(%(funcName)s:%(lineno)d)] - %(message)s"

    formatter = logging.Formatter(fmt)

    st.setFormatter(formatter)
    fh.setFormatter(formatter)

    logger.addHandler(st)
    logger.addHandler(fh)


    # logging.warning('这是晚自习作业题的日志信息')